home *** CD-ROM | disk | FTP | other *** search
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- // Binormal computation without mirroring test
- inline float3 ComputeBinormal (const float3 bumpTangent, const float3 bumpNormal);
-
- // Binormal computation with mirroring test
- inline float3 ComputeBinormal (const float3 bumpTangent, const float3 bumpNormal, const float3 normal);
-
- // Vector computation and normalization
- inline float3 ComputeVector (const float3 position, const float3 destination);
-
- // Vector computation, normalization and length
- inline float4 ComputeVectorAndLength (const float3 position, const float3 destination);
-
- // Transform a vertor in texture space
- inline float3 TextureSpaceTransform (const float3 inputVector, const float3 bumpTangent, const float3 bumpNormal, const float3 bumpBinormal);
-
- // Half View vector computation and normalization
- inline float3 ComputeHalfViewVector (const float3 lightDirection, const float3 cameraDirection);
-
- // Compute attenuation
- inline float ComputeAttenuation (const float distance, const float attenuationStart, const float attenuationEnd, const float attenuationDelta);
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- inline float3 ComputeBinormal (const float3 bumpTangent, const float3 bumpNormal)
- {
- // binormal computation based on input bumb tangent and bump normal
- return cross (bumpTangent,bumpNormal);
- }
-
- //------------------------------------------------------------------------------------------------------
-
- inline float3 ComputeBinormal (const float3 bumpTangent, const float3 bumpNormal, const float3 normal)
- {
- // binormal computation based on input bumb tangent and bump normal
- float3 binormal = cross (bumpTangent,bumpNormal);
-
- // if dot product between binormal and normal is negative, invert the binormal
- float binormalDotNormal = dot (binormal,normal);
- float3 signe = sign (binormalDotNormal);
- binormal *= signe;
-
- return binormal;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- inline float3 ComputeVector (const float3 position, const float3 destination)
- {
- float3 direction = position - destination;
- return normalize(direction);
- }
-
- //------------------------------------------------------------------------------------------------------
-
- inline float4 ComputeVectorAndLength (const float3 position, const float3 destination)
- {
- float4 direction;
-
- direction.xyz = position - destination;
- direction.w = direction.x * direction.x + direction.y * direction.y + direction.z * direction.z;
- direction.xyz *= rsqrt(direction.w);
-
- return direction;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- inline float3 TextureSpaceTransform (const float3 inputVector, const float3 bumpTangent, const float3 bumpNormal, const float3 bumpBinormal)
- {
- float3 toTextureSpace;
-
- toTextureSpace.x = dot (inputVector,bumpTangent);
- toTextureSpace.y = dot (inputVector,bumpNormal);
- //toTextureSpace.y = dot (inputVector,-bumpNormal);
- toTextureSpace.z = dot (inputVector,bumpBinormal);
-
- return toTextureSpace;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- inline float3 ComputeHalfViewVector (const float3 lightDirection, const float3 cameraDirection)
- {
- float3 halfView = lightDirection + cameraDirection;
-
- return normalize(halfView);
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-
- inline float ComputeAttenuation (const float distance, const float attenuationStart, const float attenuationEnd, const float attenuationDelta)
- {
- float attenuation;
-
- attenuation = max (distance,attenuationStart);
- attenuation = attenuationEnd - attenuation;
- attenuation = max (attenuation,0.0f);
- attenuation *= attenuationDelta;
-
- return attenuation;
- }
-
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
- //------------------------------------------------------------------------------------------------------
-